package com.cherrish.demo.bio;

import com.cherrish.demo.SocketConst;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @author cherrish
 * @time 2019-04-26 15:56
 * @name BiooClient
 * @desc:
 */
public class BioClient {

    public static void main(String[] args) {
        start();
    }
    private static void start(){
        try {
            Socket socket = new Socket(SocketConst.ADDRESS, SocketConst.PORT);
            OutputStream outputStream = socket.getOutputStream();
            String message = "Hello Server!";
            outputStream.write(message.getBytes(SocketConst.CHARSET));
            InputStream inputStream = socket.getInputStream();
            byte[] buff = new byte[1024];
            int len = inputStream.read(buff);
            System.out.println("recv from server: " + new java.lang.String(buff, 0, len));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
